package application;

import javafx.fxml.FXML;
import javafx.scene.control.Button;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import base.Manager;
import base.Person;
import db.DB_tools;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;  
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.PasswordField;
import java.net.URL;  
import java.util.ResourceBundle;  
import javafx.event.ActionEvent;  
import javafx.fxml.FXML;  
import javafx.fxml.Initializable;  
import javafx.scene.control.PasswordField;  
import javafx.scene.control.TextField;

public class CheckAttendanceController implements Initializable{
	
	@FXML
	private Button startb;
	@FXML
	private Button finishb;
	@FXML
	private Button askb;
	@FXML
	private Button bstaffinfo;
	@FXML
	private Button bcheckattendance;
	@FXML
	private Button battendance_st;
	@FXML
	private Button bdaily_ass;
	@FXML
	private Button bbulletin;
	@FXML
	private Button blogout;
	
	private Main application;
	// Event Listener on Button.onAction
	
	Person p = new Manager();
	
	public void setApp(Main application){  
        this.application = application;  
    }  
	

	
	@FXML
	public void bbulletin(ActionEvent event){  // the event of button
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotoaddBulletin(m);
		}
		else{
			application.gotoBulletin(p);
		}
		
	}
	
	@FXML
	public void gotoAssignment(ActionEvent event)
	{
		if("Manager".equals(p.getLevel()))
		{
			Manager m=(Manager)p;
			application.gotoaddAssignment(m);
		}
		else{
			application.gotoAssignment(p);
		}
	}
	
	@FXML
	public void bcheckattendance(ActionEvent event)
	{
		application.gotoCheckAttendance(p);	
	}
	

	@FXML
	public void bstaffinfo(ActionEvent event)
	{
		if("Manager".equals(p.getLevel()))
		{
			Manager m=(Manager)p;
			System.out.println("I'm Manager");
			application.gotoNamelist(m);
		}
		else
		{
			application.gotoStaffinfo(p);
		}
	}
	
	@FXML
	public void bdaily_ass(ActionEvent event)
	{
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotoaddAssignment(m);
		}
		else{
			application.gotoAssignment(p);
		}
	}
	
	@FXML
	public void battendance_st(ActionEvent event){
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotonamelist(m);
		}
		else{
			String s = String.valueOf(p.getID());
			application.gotoworkdayinfo(p, s);
		}
	}

	
	@FXML
	public void start(ActionEvent event) {		//use DB.tools function check attendance
		String a = "work";
		DB_tools.checkAttendance(a, p.getName(), p.getID());
		
	}
	
	@FXML
	public void askForLeave(ActionEvent event) {		//also use the check attendance function
		String a = "offday";
		DB_tools.checkAttendance(a, p.getName(), p.getID());
	}

	@FXML
	public void finish(ActionEvent event) {		
		String a = "xiaban";
		DB_tools.checkAttendance(a, p.getName(), p.getID());
	}
	
	@Override 
	public void initialize(URL url, ResourceBundle rb) {  
	        // TODO  
	}

	public Main getApp() {
		return application;
	}   
}
